package com.lab1;
//https://blog.csdn.net/taozi8023/article/details/51457555
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		try {
			String encoding="utf-8";
			File file=new File("example.txt");
			if(file.isFile() && file.exists()){ //判断文件是否存在
				InputStreamReader read = new InputStreamReader(
						new FileInputStream(file),encoding);//考虑到编码格式
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while((lineTxt = bufferedReader.readLine()) != null){
					System.out.println("输入命令："+ lineTxt);
					Context context = new Context(lineTxt);
					Node node = new ExpressionNode();
					node.interpret(context);
					node.execute();
					System.out.println("\n");
				}
			}else{
				System.out.println("找不到指定的文件");
			}
		} catch (Exception e) {
			System.out.println("读取文件内容出错");
			e.printStackTrace();
		}
	}
}